<style lang="scss">
@import "@/assets/css/variable";

.my {
  position: absolute;
  top: 0;
  bottom: $tabbar-height;
  width: 100%;
  background-color: $main-bgc;
  min-height: 100%;
  font-size: 1.2rem;
  overflow: auto;
  box-sizing: border-box;

  .active {
    width: 100%;
    height: 20rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    .image_van {
      border: 2px solid #fff;
      box-shadow: 0 1px 5px black;
    }

    .info-center {
      font-size: 1.8rem;
      margin-top: 10px;
      color: white;
      font-weight: bold;
    }
  }

  .panel_list {
    padding: 0 10px;
    position: relative;
    top: -15px;

    .pannel {
      background-color: white;
      border-radius: 5px;
      margin-bottom: 8px;
      color: #565656;

      .panel_body {
        display: flex;
        justify-content: space-around;

        .panel_item {
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: space-around;
          padding: 1rem 0;

          // font-size: 1.3rem;
          .cap-title {
            margin-top: 0.5rem;
            font-size: 1.2rem;
          }
        }
      }

      .panel_down {
        display: flex;
        justify-content: space-between;
        align-items: center;
        line-height: 4.5rem;
        padding: 0 14px;
        // font-size: 15px;
        border-bottom: 1px solid #f4f4f4;
      }
    }
  }

  .top-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: white;

    .info {
      display: flex;
      align-items: center;

      .info-center {
        display: flex;
        flex-direction: column;
      }

      .name {
        font-size: 1.6rem;
        margin-left: 1rem;
        font-weight: bold;
      }
    }

    .vip {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;

      .xufei {
        color: #999;
      }
    }
  }

  .fans-data-box {
    background-color: white;

    .data-title {
      font-size: 1.6rem;
      font-weight: bold;
    }

    .fans-info {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .box-item {
        // margin-top: 1.8rem;
        .cap-title {
          color: $color-subtitle;
          font-size: 1.4rem;
        }

        .num {
          margin-top: 1rem;
          font-size: 1.5rem;
          font-weight: bold;
        }
      }
    }
  }

  .yue-data-box {
    background-color: white;

    .box {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }

  .function-box {
    background-color: white;
  }
}
</style>
<template>
  <div class="my">
    <div
      class="active"
      :style="{ backgroundColor: $store.getters.getMasterColor }"
    >
      <van-image
        round
        width="8rem"
        height="8rem"
        :src="userInfo.avatar || userInfo.door_header"
        class="image_van"
      />
      <div class="info-center">
        <span class="name">{{ userInfo.nickname || userInfo.name }}</span>
      </div>
    </div>

    <div class="panel_list">
      <div class="pannel">
        <div class="panel_body">
          <div class="panel_item">
            <span>{{ myInfo.join_num || 0 }}</span>
            <span class="cap-title">总粉丝数</span>
          </div>
          <div class="panel_item">
            <span>{{ myInfo.order || 0 }}</span>
            <span class="cap-title">今日下单</span>
          </div>
          <div class="panel_item">
            <span>{{ myInfo.unsettle || 0.0 }}</span>
            <span class="cap-title">账户余额</span>
          </div>
        </div>
      </div>

      <div class="pannel">
        <div
          class="panel_down"
          v-if="userInfo.vip_status == 2"
          @click="toVIPView"
        >
          <span class="fs-14" :style="{ color: $store.getters.getMasterColor }"
            >VIP商户</span
          >
          <span class="xufei">{{ userInfo.vip_time.substr(0, 10) }}</span>
        </div>
        <div class="panel_down" v-else>
          <div class="">客流裂变系统</div>
          <van-button
            :color="$store.getters.getMasterColor"
            size="mini"
            @click="toVIPView"
            >立刻购买</van-button
          >
        </div>
        <div class="panel_body">
          <div class="panel_item" @click="system">
            <van-icon
              name="add-o"
              size="2rem"
              :color="$store.getters.getMasterColor"
            />
            <span class="cap-title">发起活动</span>
          </div>
          <div class="panel_item" @click="getMoney">
            <van-icon
              name="gold-coin-o"
              size="2rem"
              :color="$store.getters.getMasterColor"
            />
            <span class="cap-title">我要提现</span>
          </div>
          <div class="panel_item" @click="merchant">
            <van-icon
              name="shop-collect-o"
              size="2rem"
              :color="$store.getters.getMasterColor"
            />
            <span class="cap-title">商户信息</span>
          </div>
        </div>

        <div class="panel_body">
          <div class="panel_item" @click="customer">
            <van-icon
              name="manager-o "
              size="2rem"
              :color="$store.getters.getMasterColor"
            />
            <span class="cap-title">客户管理</span>
          </div>
          <div class="panel_item" @click="business">
            <van-icon
              name="records"
              size="2rem"
              :color="$store.getters.getMasterColor"
            />
            <span class="cap-title">经营数据</span>
          </div>
		  
          <div class="panel_item" @click="staffManage">
            <van-icon
              name="friends-o"
              size="2rem"
              :color="$store.getters.getMasterColor"
            />
            <span class="cap-title">核销管理</span>
          </div>
        </div>
      </div>

      <div class="pannel" style="font-siae: 1.2rem">
        <van-cell
          :title-style="{ color: '#565656' }"
          v-if="!employeesData.status"
          title="员工管理"
          is-link
          to="employeeManage"
        />
        <van-cell
          :title-style="{ color: '#565656' }"
          v-if="!employeesData.status"
          title="我的活动"
          is-link
          @click="myClick"
        />
      </div>
	  <div class="pannel" style="font-siae: 1.2rem">
	    <van-cell
	      :title-style="{ color: '#565656' }"
	      v-if="!employeesData.status"
	      title="推广员"
	      is-link
	      to="promoter"
	    />
	  </div>
    </div>
	<div class="tabbar-height"></div>
  </div>
</template>

<script>
// @ is an alias to /src
import { Image as VanImage, Toast, Dialog, Icon } from "vant";
import { Button } from "vant";
import { Cell, CellGroup } from "vant";
import { myMixins } from "@/assets/js/mixins.js";
// import wx from 'weixin-js-sdk';
export default {
  name: "My",
  mixins: [myMixins],
  components: {
    [Button.name]: Button,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Dialog.name]: Dialog,
    [Icon.name]: Icon,
    VanImage,
  },
  data() {
    return {
      openid: "",
      userInfo: "",
      myInfo: "",
      employeesData: {},
    };
  },
  created() {
    const tabbar = JSON.parse(localStorage.getItem("tabbar"));
    document.title = tabbar[3].text;
    this.getModelGN();
	// 判断链接中是否有promoter_id (推广员id)
    // console.log('this.$router', this.$route)
    const p_promoter_id = this.$route.query.promoter_id
    if(p_promoter_id&&p_promoter_id!='undefined') {
      this.$store.commit('setPPromoterId',p_promoter_id)
    }
  },
  mounted() {
    // document.title = '个人中心'
    // this.getTypeNum(this.form.introduce)
    if (process.env.NODE_ENV == "production") {
      //线上环境
      this.openid = localStorage.getItem("OPENID") || "没获取到";
    } else {
      this.openid = this.$store.state.openid || localStorage.getItem("OPENID");
    }
    if (
      this.openid == "undefined" ||
      !this.openid ||
      this.openid == undefined
    ) {
      window.location.href = `//${location.hostname}${
        location.href.indexOf("addons") > -1
          ? "/addons/youmi_activitys/public"
          : ""
      }/mobile/index.html`;
      return;
    }
    // on close
    this.getMerchantItem();
    this.getMerchantItems();
  },
  methods: {
    // 判断是否存在功能插件
    getModelGN() {
      this.$request.getModelGN().then((res) => {
        res.data.forEach((item) => {
          if (item.folder == "employeesback") {
            this.employeesData = item;
          }
        });
        console.log(this.employeesData, "this.employeesData");
      });
    },
    system() {
      this.$store.commit('setTabbarActive',2)
      this.$router.push("system");
    },
    getMoney() {
      if(this.userInfo.boss_status == 2) return this.$toast('只有您的上级可提现')
      this.$router.push("getMoney");
    },
    merchant() {
      if(this.userInfo.boss_status == 2) return this.$toast('只有您的上级可修改商户信息')
      this.$router.push("merchant");
    },
    staffManage() {
      this.$router.push("staffManage");
    },
    customer() {
      this.$store.commit("setUserInfo", this.userInfo);
      this.$router.push(`customer`);
    },
    business() {
      this.$store.commit("setUserInfo", this.userInfo);
      this.$router.push(`business`);
    },
    myClick() {
      let params = {
        openid: this.openid,
      };
      this.$request.getStaffItemall(params).then((res) => {
        if (res.ret == 400) {
          return Toast("您尚未成为员工,请去添加员工信息");
        }
        this.$router.push("staffActivity");
      });
    },
    toVIPView() {
      this.$router.push("/vip");
    },
    // 获取个人中心的总粉丝数据和今日下单量
    getMerchantItems() {
      let params = {
        openid: this.openid,
      };
      this.$request.getMerchantItems(params).then((res) => {
        if (res.ret == 200) {
          this.myInfo = res.data;
          this.$store.commit("setMyInfo", this.myInfo);
        } else {
        }
      });
    },
	// 获取商户信息
    getMerchantItem() {
      const toast = Toast.loading({
        forbidClick: true,
        message: "加载中...",
      });
      let params = {
        openid: this.openid,
      };
      this.$request.getMerchantItem(params).then((res) => {
        if (res.data.id) {
		  localStorage.setItem('merchant_id',res.data.id)
          this.userInfo = res.data;
          this.$store.commit("setUserInfo", this.userInfo);
        } else {
          //  Toast("请先去添加商户")
          this.userInfo = this.$store.state.userInfo;
          Dialog.alert({
            title: "系统提示",
            message: "请先去添加商户！",
			showCancelButton:true
          }).then(() => {
            // on close
            this.$router.push("merchant");
          });
        }
        toast.clear();
      });
    }
  },
};
</script>
